﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace DataLayer
{
    public class dluserstorylist
    {
        public DataSet UserStoryList(int sprintid)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = @"select all UserStoryId, Titel, Description, Status, EstimatedWorkload, RealWorkload, BusinessWeight, SprintID from UserStory where (SprintID = '" + sprintid + "')";

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            SqlDataAdapter myadapter = new SqlDataAdapter(querylogin);
            DataSet mydataset = new DataSet();

            myadapter.Fill(mydataset);

            return mydataset;
        }


        public void dlAddUserStory(int sprintid, string ustitel, string usdescription, int usbusweight)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = string.Format("INSERT INTO UserStory (Titel, Description, BusinessWeight, SprintID) VALUES (@ustitel,@usdescription,@usbusweight,@sprintid)");

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            querylogin.Parameters.AddWithValue("@ustitel", ustitel);
            querylogin.Parameters.AddWithValue("@usbusweight", usbusweight);
            querylogin.Parameters.AddWithValue("@sprintid", sprintid);
            querylogin.Parameters.AddWithValue("@usdescription", usdescription);

            connection.Open();
            querylogin.ExecuteNonQuery();
            connection.Close();

        }

        public void dlAddUserStory(int sprintid, string ustitel, int usbusweight)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = string.Format("INSERT INTO UserStory (Titel, BusinessWeight, SprintID) VALUES (@ustitel,@usbusweight,@sprintid)");

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            querylogin.Parameters.AddWithValue("@ustitel", ustitel);
            querylogin.Parameters.AddWithValue("@usbusweight", usbusweight);
            querylogin.Parameters.AddWithValue("@sprintid", sprintid);

            connection.Open();
            querylogin.ExecuteNonQuery();
            connection.Close();

        }

    }
}
